//https://leetcode.cn/problems/find-largest-value-in-each-tree-row/

class Solution {
public:
    vector<int> largestValues(TreeNode* root) {
        vector<int> ret;
        queue<TreeNode*> q;

        if (root == nullptr) return ret;

        q.push(root);

        while (q.size())
        {
            int sz = q.size();
            int num = INT_MIN;
            for (int i = 0; i < sz; i++)
            {
                TreeNode* top = q.front();
                q.pop();

                num = max(num, top->val);


                if (top->left) q.push(top->left);
                if (top->right) q.push(top->right);

            }
            ret.push_back(num);
        }

        return ret;

    }
};